const http = require("../../../utils/http.js")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        feedbackList: [],
        feedback: {
            content: "",
            anonymous: 1
        },
        pageInfo: {
            page: 1,
            limit: 5,
            pages: 0
        },
        showDialog: false,
        checked: true,
        beforeClose(action) {
            return action !== "confirm";
        }
    },
    scrollToBottom() {
        if (this.data.pageInfo.page < this.data.pageInfo.pages) {
            this.setData({
                "pageInfo.page": this.data.pageInfo.page + 1
            })
            this.getFeedbackList()
        } else {
            wx.showToast({title: "没有更多数据！"})
        }
    },
    getFeedbackList() {
        http.get('wx/vip/feedback/page', this.data.pageInfo).then(data => {
            if (data) {
                this.setData({
                    feedbackList: [...this.data.feedbackList, ...data.records],
                    "pageInfo.pages": data.pages
                })
            }
        })
    },
    showFeedback() {
        this.setData({
            feedback: {
                content: "",
                anonymous: 1
            },
            showDialog: true
        })
    },
    onChange(e) {
        this.setData({
            checked: e.detail,
            "feedback.anonymous": e.detail ? 1 : 2
        })
    },
    getContent(e) {
        this.setData({
            "feedback.content": e.detail
        })
    },
    dialogClose() {
        this.setData({
            feedback: {
                content: "",
                anonymous: 1
            }
        })
    },
    dialogConfirm() {
        if (!this.data.feedback.content) {
            wx.showToast({title: "请输入内容！", icon: "error"})
            return false;
        }
        http.post('wx/vip/feedback/save', this.data.feedback).then(() => {
            wx.showToast({title: "发送成功！", icon: "success"})
            this.setData({
                showDialog: false,
                feedbackList: [],
                pageInfo: {
                    page: 1,
                    limit: 5,
                    pages: 0
                }
            })
            this.getFeedbackList()
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.getFeedbackList()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})
